/*
 *    Copyright (c) 2018-2025, envpro All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: envpro
 */
package com.iwomy.envpro.platform.controller;

import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.security.annotation.Inner;
import com.iwomy.envpro.platform.VO.PollutionSourceAnalysisVO;
import com.iwomy.envpro.platform.dto.*;
import com.iwomy.envpro.platform.service.AnalysisJudgmentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 分析研判
 *
 * @author envpro
 * @date 2019-03-31 16:00:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/analysisJudgment")
@Slf4j
public class AnalysisJudgmentController {

	@Resource
	private AnalysisJudgmentService analysisJudgmentService;


	/**
	 * 动态云图
	 *
	 * @return R
	 */
	@GetMapping("dynamicCloudMap")
	public R dynamicCloudMap(@ParameterObject DynamicCloudMapDTO dynamicCloudMap) {
		try {
			return R.ok(analysisJudgmentService.dynamicCloudMap(dynamicCloudMap));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 趋势分析
	 *
	 * @return R
	 */
	@GetMapping("trendAnalysis")
	public R trendAnalysis(@ParameterObject TrendAnalysisDTO trendAnalysis) {
		try {
			return R.ok(analysisJudgmentService.trendAnalysis(trendAnalysis));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 污染分析
	 *
	 * @return R
	 */
	@PostMapping("pollutionAnalysis")
	public R pollutionAnalysis(@RequestBody PollutionAnalysisDTO pollutionAnalysis) {
		try {
			return R.ok(analysisJudgmentService.pollutionAnalysis(pollutionAnalysis));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 污染源分析
	 *
	 * @return R
	 */
	@PostMapping("pollutionSourceAnalysis")
	public R pollutionSourceAnalysis(@RequestBody PollutionAnalysisDTO pollutionAnalysis) {
		List<PollutionSourceAnalysisVO> list = new ArrayList<>();
		for (Long monitorEquipmentId : pollutionAnalysis.getMonitorEquipmentIds()) {
			pollutionAnalysis.setMonitorEquipmentId(monitorEquipmentId);
			PollutionSourceAnalysisVO pollutionSourceAnalysisVO = null;
			try {
				pollutionSourceAnalysisVO = analysisJudgmentService.pollutionSourceAnalysis(pollutionAnalysis);
			} catch (Exception e) {
				return R.failed(e.getMessage());
			}
			list.add(pollutionSourceAnalysisVO);
		}
		return R.ok(list);
	}


	/**
	 * 同比
	 *
	 * @param year
	 * @return
	 */
	@PostMapping("yearOnYear")
	public R yearOnYear(@RequestBody YearOnYearDTO year) {
		try {
			return R.ok(analysisJudgmentService.yearOnYear(year));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}

	/**
	 * 环比
	 *
	 * @param sequentialGrowthDTO
	 * @return
	 */
	@PostMapping("sequentialGrowth")
	public R sequentialGrowth(@RequestBody SequentialGrowthDTO sequentialGrowthDTO) {

		try {
			return R.ok(analysisJudgmentService.sequentialGrowth(sequentialGrowthDTO));
		} catch (Exception e) {
			return R.failed(e.getMessage());
		}
	}


}
